﻿/***********************************************************************
 * CLR 版本: 4.0.30319.225
 * 工程名称: $projectname$
 * 命名空间: Toulr.Core.Services
 * 文件名称: GoodsService
 * 描    述: 提供商品信息维护 管理接口实现
 * 作    者: 18901309129@189.cn
 * 登录用户: hyyu
 * 创建时间: 2011-5-28 16:10:53
 * 创建年份: 2011
 * Update History: 
 ***********************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using Toulr.Domains;
using Toulr.Domains.Business;
using Toulr.Domains.System;
using Toulr.Models;
using Toulr.Models.Enums;
using Toulr.Services;

namespace Toulr.Core.Services
{
    /// <summary>
    /// GoodsService 的摘要说明。
    /// </summary>
    public class GoodsService : IGoodsService
    {
        #region 商品相关

        private static IList<Goods> SearchGoodss(int infoCategoriesId, int shopId, float maxOriginalPrice,
                                             float minOriginalPrice, float maxOfferPriceDiscount,
                                             float minOfferPriceDiscount, float maxConcessionsPrice,
                                             float minConcessionsPrice, int maxSaleCount, int minSaleCount, int maxScore,
                                             int minScore, string goodsName, string goodsDescription,
                                             IEnumerable<GoodsOrderType> lstGoodsOrderType)
        {
            var obj = from g in DomainContext.Instance.Goodses
                      select g;
            if (infoCategoriesId != -1)
                obj = obj.Where(g => GetInfoCategoriesIds(infoCategoriesId, null).Contains(g.InfoCategory.Id));
            if (shopId != -1)
                obj = obj.Where(g => g.Shop.Id == shopId);
            if (maxOriginalPrice != -1)
                obj = obj.Where(g => g.OriginalPrice <= maxOriginalPrice);
            if (minOriginalPrice != -1)
                obj = obj.Where(g => g.OriginalPrice >= maxOriginalPrice);
            if (maxOfferPriceDiscount != -1)
                obj = obj.Where(g => g.OfferPriceDiscount <= maxOfferPriceDiscount);
            if (minOfferPriceDiscount != -1)
                obj = obj.Where(g => g.OfferPriceDiscount >= minOfferPriceDiscount);
            if (maxConcessionsPrice != -1)
                obj = obj.Where(g => (g.OriginalPrice - g.OfferPriceDiscount) <= maxConcessionsPrice);
            if (minConcessionsPrice != -1)
                obj = obj.Where(g => (g.OriginalPrice - g.OfferPriceDiscount) >= minConcessionsPrice);
            if (maxSaleCount != -1)
                obj = obj.Where(g => g.SaleCount <= maxSaleCount);
            if (minSaleCount != -1)
                obj = obj.Where(g => g.SaleCount >= minSaleCount);
            if (maxScore != -1)
                obj = obj.Where(g => g.Score <= maxScore);
            if (minScore != -1)
                obj = obj.Where(g => g.Score >= minScore);
            if (!string.IsNullOrEmpty(goodsName))
                obj = obj.Where(g => g.GoodName.Contains(goodsName));
            if (!string.IsNullOrEmpty(goodsDescription))
                obj = obj.Where(g => g.GoodDescription.Contains(goodsDescription));
            if (lstGoodsOrderType != null)
            {
                foreach (GoodsOrderType t in lstGoodsOrderType)
                {
                    switch (t)
                    {
                        case GoodsOrderType.ScoreDesc:
                            obj = obj.OrderByDescending(g => g.Score);
                            break;
                        case GoodsOrderType.ScoreAsc:
                            obj = obj.OrderBy(g => g.Score);
                            break;
                        case GoodsOrderType.SaleCountDesc:
                            obj = obj.OrderByDescending(g => g.SaleCount);
                            break;
                        case GoodsOrderType.SaleCountAsc:
                            obj = obj.OrderBy(g => g.SaleCount);
                            break;
                        case GoodsOrderType.OriginalPriceDesc:
                            obj = obj.OrderByDescending(g => g.OriginalPrice);
                            break;
                        case GoodsOrderType.OriginalPriceAsc:
                            obj = obj.OrderBy(g => g.OriginalPrice);
                            break;
                        case GoodsOrderType.OfferPriceDiscountDesc:
                            obj = obj.OrderByDescending(g => g.OfferPriceDiscount);
                            break;
                        case GoodsOrderType.OfferPriceDiscountAsc:
                            obj = obj.OrderBy(g => g.OfferPriceDiscount);
                            break;
                        case GoodsOrderType.GoodNameDesc:
                            obj = obj.OrderByDescending(g => g.GoodName);
                            break;
                        case GoodsOrderType.GoodNameAsc:
                            obj = obj.OrderBy(g => g.GoodName);
                            break;

                    }
                }
            }

            return obj.ToList();
        }

        private static Goods GetGoods(int goodsId)
        {
            var lstGoods = SearchGoodss(goodsId, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, null, null, null);
            if (lstGoods == null || lstGoods.Count == 0)
            {
                return null;
            }
            return lstGoods[0];
        }

        /// <summary>
        /// 获取全部商品列表
        /// </summary>
        /// <param name="lstGoodsOrderType">指定一个或多个排序条件，为null时不考虑该条件</param>
        /// <returns></returns>
        /// hyyu 20110514
        public ActionResult<IList<Goods>> GetGoodss(IList<GoodsOrderType> lstGoodsOrderType)
        {
            try
            {
                IList<Goods> lstGoods = SearchGoodss(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, null, null,
                                                     lstGoodsOrderType);
                if (lstGoods == null)
                    return new ActionResult<IList<Goods>>(1, "未知错误", null);
                if (lstGoods.Count == 0)
                    return new ActionResult<IList<Goods>>(0, "没有符合条件的记录", lstGoods);
                return new ActionResult<IList<Goods>>(0, "查询商品信息成功", lstGoods);
            }
            catch (Exception ex)
            {
                //todo 记录错误日志
                return new ActionResult<IList<Goods>>(1, ex.Message, null);
            }
        }

        /// <summary>
        /// 获取匹配商品名称或描述的全部商品列表
        /// </summary>
        /// <param name="goodsName">商品名称 为null时不考虑该条件</param>
        /// <param name="goodsDescription">商品描述 为null时不考虑该条件</param>
        /// <param name="lstGoodsOrderType">指定一个或多个排序条件，为null时不考虑该条件</param>
        /// <returns></returns>
        /// hyyu 20110514
        public ActionResult<IList<Goods>> GetGoodss(string goodsName, string goodsDescription, IList<GoodsOrderType> lstGoodsOrderType)
        {
            try
            {
                IList<Goods> lstGoods = SearchGoodss(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, goodsName,
                                                     goodsDescription, lstGoodsOrderType);
                if (lstGoods == null)
                    return new ActionResult<IList<Goods>>(1, "未知错误", null);
                if (lstGoods.Count == 0)
                    return new ActionResult<IList<Goods>>(0, "没有符合条件的记录", lstGoods);
                return new ActionResult<IList<Goods>>(0, "查询商品信息成功", lstGoods);
            }
            catch (Exception ex)
            {
                //todo 记录错误日志
                return new ActionResult<IList<Goods>>(1, ex.Message, null);
            }
        }

        /// <summary>
        /// 获取某一类商品列表
        /// </summary>
        /// <param name="infoCategoriesId">商品分类ID 为-1时不考虑该条件</param>
        /// <param name="lstGoodsOrderType">指定一个或多个排序条件，为null时不考虑该条件</param>
        /// <returns></returns>
        /// hyyu 20110514
        public ActionResult<IList<Goods>> GetGoodssBynfoCategoriesId(int infoCategoriesId, IList<GoodsOrderType> lstGoodsOrderType)
        {
            try
            {
                IList<Goods> lstGoods = SearchGoodss(infoCategoriesId, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, null,
                                                     null, lstGoodsOrderType);
                if (lstGoods == null)
                    return new ActionResult<IList<Goods>>(1, "未知错误", null);
                if (lstGoods.Count == 0)
                    return new ActionResult<IList<Goods>>(0, "没有符合条件的记录", lstGoods);
                return new ActionResult<IList<Goods>>(0, "查询商品信息成功", lstGoods);
            }
            catch (Exception ex)
            {
                //todo 记录错误日志
                return new ActionResult<IList<Goods>>(1, ex.Message, null);
            }
        }

        /// <summary>
        /// 获取某一店铺的商品列表
        /// </summary>
        /// <param name="shopId">店铺ID 为-1时不考虑该条件</param>
        /// <param name="lstGoodsOrderType">指定一个或多个排序条件，为null时不考虑该条件</param>
        /// <returns></returns>
        /// hyyu 20110514
        public ActionResult<IList<Goods>> GetGoodssByShop(int shopId, IList<GoodsOrderType> lstGoodsOrderType)
        {
            try
            {
                IList<Goods> lstGoods = SearchGoodss(-1, shopId, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, null, null,
                                                     lstGoodsOrderType);
                if (lstGoods == null)
                    return new ActionResult<IList<Goods>>(1, "未知错误", null);
                if (lstGoods.Count == 0)
                    return new ActionResult<IList<Goods>>(0, "没有符合条件的记录", lstGoods);
                return new ActionResult<IList<Goods>>(0, "查询商品信息成功", lstGoods);
            }
            catch (Exception ex)
            {
                //todo 记录错误日志
                return new ActionResult<IList<Goods>>(1, ex.Message, null);
            }
        }

        /// <summary>
        /// 获取原价在指定范围内的商品列表
        /// </summary>
        /// <param name="maxOriginalPrice">商品原价最大值(小于等于) 为-1时不考虑该条件 </param>
        /// <param name="minOriginalPrice">商品原价最小值(大于等于) 为-1时不考虑该条件</param>
        /// <param name="lstGoodsOrderType">指定一个或多个排序条件，为null时不考虑该条件</param>
        /// <returns></returns>
        /// hyyu 20110514
        public ActionResult<IList<Goods>> GetGoodssByOriginalPrice(float maxOriginalPrice, float minOriginalPrice,
                                                            IList<GoodsOrderType> lstGoodsOrderType)
        {
            try
            {
                IList<Goods> lstGoods = SearchGoodss(-1, -1, maxOriginalPrice, minOriginalPrice, -1, -1, -1, -1, -1, -1,
                                                     -1, -1, null,
                                                     null, lstGoodsOrderType);
                if (lstGoods == null)
                    return new ActionResult<IList<Goods>>(1, "未知错误", null);
                if (lstGoods.Count == 0)
                    return new ActionResult<IList<Goods>>(0, "没有符合条件的记录", lstGoods);
                return new ActionResult<IList<Goods>>(0, "查询商品信息成功", lstGoods);
            }
            catch (Exception ex)
            {
                //todo 记录错误日志
                return new ActionResult<IList<Goods>>(1, ex.Message, null);
            }
        }

        /// <summary>
        /// 获取折扣价在指定范围内的商品列表
        /// </summary>
        /// <param name="maxOfferPriceDiscount">商品折后价最大值(小于等于) 为-1时不考虑该条件</param>
        /// <param name="minOfferPriceDiscount">商品折后价最小值(大于等于) 为-1时不考虑该条件</param>
        /// <param name="lstGoodsOrderType">指定一个或多个排序条件，为null时不考虑该条件</param>
        /// <returns></returns>
        /// hyyu 20110514
        public ActionResult<IList<Goods>> GetGoodssByOfferPriceDiscount(float maxOfferPriceDiscount,
                                                                 float minOfferPriceDiscount,
                                                                 IList<GoodsOrderType> lstGoodsOrderType)
        {
            try
            {
                IList<Goods> lstGoods = SearchGoodss(-1, -1, -1, -1, maxOfferPriceDiscount, minOfferPriceDiscount, -1,
                                                     -1, -1, -1, -1, -1, null,
                                                     null, lstGoodsOrderType);
                if (lstGoods == null)
                    return new ActionResult<IList<Goods>>(1, "未知错误", null);
                if (lstGoods.Count == 0)
                    return new ActionResult<IList<Goods>>(0, "没有符合条件的记录", lstGoods);
                return new ActionResult<IList<Goods>>(0, "查询商品信息成功", lstGoods);
            }
            catch (Exception ex)
            {
                //todo 记录错误日志
                return new ActionResult<IList<Goods>>(1, ex.Message, null);
            }
        }

        /// <summary>
        /// 获取优惠价在指定范围内的商品列表
        /// </summary>
        /// <param name="maxConcessionsPrice">商品优惠价最大值(小于等于) 为-1时不考虑该条件</param>
        /// <param name="minConcessionsPrice">商品优惠价最大值(大于等于) 为-1时不考虑该条件</param>
        /// <param name="lstGoodsOrderType">指定一个或多个排序条件，为null时不考虑该条件</param>
        /// <returns></returns>
        /// hyyu 20110514
        public ActionResult<IList<Goods>> GetGoodssByConcessionsPrice(float maxConcessionsPrice, float minConcessionsPrice,
                                                               IList<GoodsOrderType> lstGoodsOrderType)
        {
            try
            {
                IList<Goods> lstGoods = SearchGoodss(-1, -1, -1, -1, -1, -1, maxConcessionsPrice, minConcessionsPrice,
                                                     -1, -1, -1, -1, null,
                                                     null, lstGoodsOrderType);
                if (lstGoods == null)
                    return new ActionResult<IList<Goods>>(1, "未知错误", null);
                if (lstGoods.Count == 0)
                    return new ActionResult<IList<Goods>>(0, "没有符合条件的记录", lstGoods);
                return new ActionResult<IList<Goods>>(0, "查询商品信息成功", lstGoods);
            }
            catch (Exception ex)
            {
                //todo 记录错误日志
                return new ActionResult<IList<Goods>>(1, ex.Message, null);
            }
        }

        /// <summary>
        /// 获取销售数量在指定范围内的商品列表
        /// </summary>
        /// <param name="maxSaleCount">商品销售数量最大值(小于等于) 为-1时不考虑该条件</param>
        /// <param name="minSaleCount">商品销售数量最小值(大于等于) 为-1时不考虑该条件</param>
        /// <param name="lstGoodsOrderType">指定一个或多个排序条件，为null时不考虑该条件</param>
        /// <returns></returns>
        public ActionResult<IList<Goods>> GetGoodssBySaleCount(int maxSaleCount, int minSaleCount,
                                                        IList<GoodsOrderType> lstGoodsOrderType)
        {
            try
            {
                IList<Goods> lstGoods = SearchGoodss(-1, -1, -1, -1, -1, -1, -1, -1, maxSaleCount, minSaleCount, -1, -1, null,
                                     null, lstGoodsOrderType);
                if (lstGoods == null)
                    return new ActionResult<IList<Goods>>(1, "未知错误", null);
                if (lstGoods.Count == 0)
                    return new ActionResult<IList<Goods>>(0, "没有符合条件的记录", lstGoods);
                return new ActionResult<IList<Goods>>(0, "查询商品信息成功", lstGoods);
            }
            catch (Exception ex)
            {
                //todo 记录错误日志
                return new ActionResult<IList<Goods>>(1, ex.Message, null);
            }
        }

        /// <summary>
        /// 获取得分值在指定范围内的商品列表
        /// </summary>
        /// <param name="maxScore">商品得分值(小于等于) 为-1时不考虑该条件</param>
        /// <param name="minScore">商品得分值(大于等于) 为-1时不考虑该条件</param>
        /// <param name="lstGoodsOrderType">指定一个或多个排序条件，为null时不考虑该条件</param>
        /// <returns></returns>
        /// hyyu 20110514
        public ActionResult<IList<Goods>> GetGoodssBymaxScore(int maxScore, int minScore,
                                                       IList<GoodsOrderType> lstGoodsOrderType)
        {
            try
            {
                IList<Goods> lstGoods = SearchGoodss(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, maxScore, minScore, null,
                                                     null, lstGoodsOrderType);
                if (lstGoods == null)
                    return new ActionResult<IList<Goods>>(1, "未知错误", null);
                if (lstGoods.Count == 0)
                    return new ActionResult<IList<Goods>>(0, "没有符合条件的记录", lstGoods);
                return new ActionResult<IList<Goods>>(0, "查询商品信息成功", lstGoods);
            }
            catch (Exception ex)
            {
                //todo 记录错误日志
                return new ActionResult<IList<Goods>>(1, ex.Message, null);
            }
        }

        /// <summary>
        /// 获取指定条件的商品列表
        /// </summary>
        /// <param name="infoCategoriesId">商品分类ID 为-1时不考虑该条件</param>
        /// <param name="shopId">店铺ID 为-1时不考虑该条件</param>
        /// <param name="maxOriginalPrice">商品原价最大值(小于等于) 为-1时不考虑该条件 </param>
        /// <param name="minOriginalPrice">商品原价最小值(大于等于) 为-1时不考虑该条件</param>
        /// <param name="maxOfferPriceDiscount">商品折后价最大值(小于等于) 为-1时不考虑该条件</param>
        /// <param name="minOfferPriceDiscount">商品折后价最小值(大于等于) 为-1时不考虑该条件</param>
        /// <param name="maxConcessionsPrice">商品优惠价最大值(小于等于) 为-1时不考虑该条件</param>
        /// <param name="minConcessionsPrice">商品优惠价最大值(大于等于) 为-1时不考虑该条件</param>
        /// <param name="maxSaleCount">商品销售数量最大值(小于等于) 为-1时不考虑该条件</param>
        /// <param name="minSaleCount">商品销售数量最小值(大于等于) 为-1时不考虑该条件</param>
        /// <param name="maxScore">商品得分值(小于等于) 为-1时不考虑该条件</param>
        /// <param name="minScore">商品得分值(大于等于) 为-1时不考虑该条件</param>
        /// <param name="goodsName">商品名称 为null时不考虑该条件</param>
        /// <param name="goodsDescription">商品描述 为null时不考虑该条件</param>
        /// <param name="lstGoodsOrderType">指定一个或多个排序条件，为null时不考虑该条件</param>
        /// <returns></returns>
        /// hyyu 20110514
        public ActionResult<IList<Goods>> GetGoodss(int infoCategoriesId, int shopId, float maxOriginalPrice,
                                             float minOriginalPrice, float maxOfferPriceDiscount,
                                             float minOfferPriceDiscount, float maxConcessionsPrice,
                                             float minConcessionsPrice, int maxSaleCount, int minSaleCount, int maxScore,
                                             int minScore, string goodsName, string goodsDescription,
                                             IList<GoodsOrderType> lstGoodsOrderType)
        {
            try
            {
                IList<Goods> lstGoods = SearchGoodss(infoCategoriesId, shopId, maxOriginalPrice, minOriginalPrice,
                                                     maxOfferPriceDiscount, minOfferPriceDiscount, maxConcessionsPrice,
                                                     minConcessionsPrice, maxSaleCount, minSaleCount, maxScore,
                                                     minScore, goodsName, goodsDescription, lstGoodsOrderType);
                if (lstGoods == null)
                    return new ActionResult<IList<Goods>>(1, "未知错误", null);
                if (lstGoods.Count == 0)
                    return new ActionResult<IList<Goods>>(0, "没有符合条件的记录", lstGoods);
                return new ActionResult<IList<Goods>>(0, "查询商品信息成功", lstGoods);
            }
            catch (Exception ex)
            {
                //todo 记录错误日志
                return new ActionResult<IList<Goods>>(1, ex.Message, null);
            }
        }

        /// <summary>
        /// 添加商品
        /// </summary>
        /// <param name="goods"></param>
        /// <returns></returns>
        /// hyyu 20110514
        public ActionResult<Goods> AddGoods(Goods goods)
        {
            //todo 没有办法验证商品是否重复录入，KEY是自动标识，商品名称又必须允许重复

            if (goods == null)
                return new ActionResult<Goods>(1, "要添加的商品信息为空", null);
            if (!string.IsNullOrEmpty(goods.GoodName))
                return new ActionResult<Goods>(1, "商品名称不能为空", null);
            if (!string.IsNullOrEmpty(goods.GoodDescription))
                return new ActionResult<Goods>(1, "商品描述不能为空", null);
            if (goods.InfoCategory == null || GetInfoCategories(goods.InfoCategory.Id) == null)
                return new ActionResult<Goods>(1, "商品分类不存在", null);
            //if (goods.Shop == null || GetShop(goods.Shop.Id) != null)
            //    return new ActionResult<Goods>(1,"商品所属店铺不存在",null);

            try
            {
                var predicate = new Repository<Goods>();
                predicate.Add(goods);
                return new ActionResult<Goods>(0, "添加商品成功", goods);
            }
            catch (Exception ex)
            {
                //todo 记录错误日志
                return new ActionResult<Goods>(0, ex.Message, null);
            }
        }

        /// <summary>
        /// 修改商品信息
        /// </summary>
        /// <param name="goods"></param>
        /// <returns></returns>
        /// hyyu 20110514
        public ActionResult<Goods> UpdateGoods(Goods goods)
        {
            if (goods == null)
                return new ActionResult<Goods>(1, "要更新的商品为信息为空", goods);
            if (GetGoods(goods.Id) == null)
                return new ActionResult<Goods>(1, "要更新的商品不存在", goods);
            if (goods.InfoCategory == null || GetInfoCategories(goods.InfoCategory.Id) == null)
                return new ActionResult<Goods>(1, "要更新的商品所属类别不存在", goods);
            //if(goods.Shop==null || GetShop(goods.Shop.Id)==null)
            //    return new ActionResult<Goods>(1,"要更新的商品所属店铺不存在",goods);

            try
            {
                var repository = new Repository<Goods>();
                repository.Update(goods);
                return new ActionResult<Goods>(1, "更新商品信息成功", goods);
            }
            catch (Exception ex)
            {
                //todo 记录错误日志
                return new ActionResult<Goods>(1, ex.Message, goods);
            }
        }

        /// <summary>
        /// 删除商品信息
        /// </summary>
        /// <param name="goods"></param>
        /// <returns></returns>
        /// hyyu 20110514
        public ActionResult<Goods> DeleteGoods(Goods goods)
        {
            try
            {
                if (goods == null)
                    return new ActionResult<Goods>(1, "要删除的商品信息为空", null);
                if (GetGoods(goods.Id) == null)
                    return new ActionResult<Goods>(1, "要删除的商品信息不存在", null);
                var repository = new Repository<Goods>();
                repository.Delete(goods);
                return new ActionResult<Goods>(0, "删除商品信息成功", goods);
            }
            catch (Exception ex)
            {
                //todo 记录错误日志
                return new ActionResult<Goods>(1, ex.Message, null);
            }
        }

        /// <summary>
        /// 删除商品信息
        /// </summary>
        /// <param name="goodsId"></param>
        /// <returns></returns>
        /// hyyu 20110514
        public ActionResult<Goods> DeleteGoods(int goodsId)
        {
            try
            {
                var goods = new Goods { Id = goodsId };
                return DeleteGoods(goods);
            }
            catch (Exception ex)
            {
                //todo 记录错误日志
                return new ActionResult<Goods>(1, ex.Message, null);
            }
        }

        private static IList<int> GetInfoCategoriesIds(int parentId, IList<int> lstParentIds)
        {
            //根据一个类别的ID，获取下面所有层次的子类别ID(已经启用的)

            if (lstParentIds == null)
            {
                lstParentIds = new List<int> { parentId };
            }

            var lstInfoCategoriess = GetInfoCategoriess(-1, null, -1, true);
            if (lstInfoCategoriess != null && lstInfoCategoriess.Count > 0)
            {
                foreach (var infoCategoriese in lstInfoCategoriess)
                {
                    if (lstParentIds.Contains(infoCategoriese.Id))
                        lstParentIds.Add(infoCategoriese.Id);
                    lstParentIds = GetInfoCategoriesIds(infoCategoriese.Id, lstParentIds);
                }
            }

            return lstParentIds;
        }

        private static InfoCategories GetInfoCategories(int id)
        {
            var result = GetInfoCategoriess(id, null, -1, null);
            if (result == null || result.Count == 0)
                return null;
            return result[0];

        }

        private static IList<InfoCategories> GetInfoCategoriess(int id, string categoryName, int parentId, bool? enabled)
        {
            var obj = from ic in DomainContext.Instance.InfoCategorieses
                      select ic;
            if (id != -1)
                obj = obj.Where(ic => ic.Id == id);
            if (!string.IsNullOrEmpty(categoryName))
                obj = obj.Where(ic => ic.CategoryName.Contains(categoryName));
            if (parentId != -1)
                obj = obj.Where(ic => ic.ParentId == parentId);
            if (enabled != null)
                obj = obj.Where(ic => ic.Enabled == enabled);
            return obj.ToList();
        }



        #endregion
    }
}
